#!/bin/bash

home=$(cd $(dirname $0); pwd)
cd $home

##### check #####
old=$($home/status.sh)
if [ "$old" != "" ]; then
  echo error: the server already started, pid: $old
  echo please stop it first.
  exit -1
fi
##### check end #####

##### extend #####
ARGS=$*
##### extend end #####

##### config #####
console="console.log"


# JVM options
JAVA_OPTS="$JAVA_OPTS -Xms1024m -Xmx2048m"
JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -Xloggc:$home/full-gc.log"
#JAVA_OPTS="$JAVA_OPTS -agentlib:jdwp=transport=dt_socket,suspend=n,server=y,address=0.0.0.0:8000"
##### config end #####

##### exec #####
echo ==============================starting at $(date +"%Y-%m-%d %H:%M:%S")============================== >> $console
mainJar=$home/*.jar
java $JAVA_OPTS  -jar $mainJar $ARGS >> $console 2>&1 &
pid=$!
echo $pid > $home/pid
echo "pid: $pid"
##### exec end #####
